<#include "/layout/layout.ftl">
<#import "/layout/macro.ftl" as macro>
<#assign css>

</#assign>
<#assign js>

<script>

    $(".btn-submit").click(function () {
        if (!validform().form()) {
            return
        }
        var code = $("#msgcode").val();

        if($("#id").val()==""&&!checkMsgCode(code)){
          return;
        }

        // if(!checkMsgCode($("#msgcode").val()){
        //     return;
        // }

        $.ajax({
            type: "POST",
            url: "${ctx!}/agent/edit",
            data: $(".form-edit").serialize(),
            dataType: "JSON",
            success: function (res) {
                layer.msg(res.message, {
                    time: 2000
                }, function () {
                    if (res.code == 0) {
                        window.location.href = "${ctx!}/agent/index";
                    }
                    // location.reload();
                });
            }
        });

    })

    //声明一个函数
    function validform() {
        return $("#form-article-add").validate({
            rules : {
                phone : {
                    required : true,
                    number:true,
                    min:11,
                    remote: {
                        type: "get",
                        url: "${ctx!}/agent/checkphone",
                        data: {
                            phone: function() {
                                return $("#phone").val();
                            }
                        },
                        dataType: "JSON",
                        dataFilter: function(data, type) {
                            if($("#phone").val()==$("#phone2").val()){
                                return true;
                            }
                            var data=JSON.parse(data)
                            if (data.code ==-1)
                                return false;
                            else
                                return true;
                        }
                    }
                },
                nickname : {
                    required : true
                }
            },
            messages : {
                phone : {
                    required : "手机号不能为空",
                    number:"手机号不正确",
                     min:"手机号不正确",
                    remote: "手机号重复"
                },
                nickname : {
                    required : "昵称不能为空",

                }
            }
        });
    }



</script>
</#assign>
<@layout title="代理用户编辑" active="user">
<!-- Content Header (Page header) -->
<section class="content-header">
    <h1>
        代理用户编辑
        <small>编辑代理用户详细信息</small>
    </h1>
    <ol class="breadcrumb">
        <li><a href="#"><i class="fa fa-cog"></i> 系统</a></li>
        <li><a href="#"><i class="fa fa-list-ul"></i> 代理管理</a></li>
        <li class="active"><i class="fa fa-edit"></i> 代理用户编辑</li>
    </ol>
</section>
<!-- Main content -->
<section class="content">


    <div class="row">
        <div class="col-md-12">
            <!-- Default box -->
            <div class="box  box-primary">
                <form id="form-article-add" class="form-horizontal form-edit" method="post" action="${ctx!}/user/edit">
                    <div class="box-body">
                        <input type="hidden" id="id" name="id" value="${user.id}">
                        <div class="form-group">
                            <label class="col-sm-2 control-label">昵称<span style="color:red;"> *</span>：</label>
                            <div class="col-sm-8">
                                <input id="nickname" name="nickname" class="form-control" type="text"
                                       value="${user.nickname}"  maxlength="6" >
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">身份证号码：</label>
                            <div class="col-sm-8">
                                <input id="idCard" name="idCard" class="form-control" type="text"
                                       value="${user.idCard}" maxlength="18">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">微信号：</label>
                            <div class="col-sm-8">
                                <input id="wechat" name="wechat" class="form-control" type="text" value="${user.wechat}">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">可提现金额：</label>
                            <div class="col-sm-8">
                                <input id="ableMoney" disabled name="ableMoney" class="form-control" type="text" value="${user.ableMoney}">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">电话号码<span style="color:red;"> *</span>：</label>
                            <div class="col-sm-8">
                                <input id="phone"  <#if user?exists> readonly</#if> name="phone" class="form-control" type="text" value="${user.phone}">
                                <input id="phone2" name="phone2" class="form-control" type="hidden" value="${user.phone}" minlength="4" maxlength="12">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">状态：</label>
                            <div class="col-sm-8">
                                <select name="status" class="form-control"  disabled >
                                    <option value="0" <#if user.status == 0>selected="selected"</#if>>未使用</option>
                                    <option value="1" <#if user.status == 1>selected="selected"</#if>>已使用</option>
                                    <option value="1" <#if user.status == 2>selected="selected"</#if>>已封号</option>
                                </select>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">描述：</label>
                            <div class="col-sm-8">
                                <textarea maxlength="200" id="description" name="description" class="form-control"
                                          rows="6">${user.description}</textarea>
                            </div>
                        </div>

                        <div class="form-group <#if user?exists> hidden</#if>" >
                            <label class="col-sm-2 control-label"></label>

                                <div class="form-inline col-sm-8">
                                    <input id="msgcode" type="text" class="form-control" placeholder="请输入验证码" />
                                    <input type="button"  class="btn " id="verify_refresh" onclick="getMsgNum(this)" value="免费获取验证码"/>
                                </div>

                        </div>



                        </div>

                    <div class="box-footer">
                        <button type="button" class="btn btn-default btn-back">返回</button>
                        <button type="button" class="btn btn-info pull-right btn-submit">提交</button>
                    </div>
                </form>
            </div>
            <!-- /.box -->
        </div>
    </div>
</section>
<!-- /.content -->
</@layout>
